$(function(){
	showOrder();
})
function showOrder(){
	var thisUrl=document.URL;
	var getVal=thisUrl.split('?')[1];
	var orderDetailId=getVal.split('=')[1];
	
	$.ajax({
		data:{"orderDeatilId":orderDetailId},
		url:'GetOneOrderDetailServlet',
		type:'POST',
		dataType:"json",
		success:function(response){
			$("#content").append("<table>\
					<thead>\
			            <tr>\
			                <th><div class='right'>Purchasing Date:&nbsp;&nbsp;</div></th>\
			                <th><div class='left'>"+response.order.CreateDate+"</div></th>\
			                <th>&nbsp;</th>\
			                <th><div class='right'>Order ID:&nbsp;</div></th>\
			                <th><div class='left'>&nbsp;"+response.order.OrderId+"</div></th>\
			            </tr>\
			        </thead>\
					<tbody id="+response.order.OrderId+">\
			        </tbody>\
					</table>\
					<div style='width:440px; margin:0 auto;'><textarea id='commentArea' cols='60' rows='10'></textarea></div>\
					<div style='width:440px; margin:10px auto;'><button id='sub' onclick='doComment("+response.book.BookId+","+response.order.OrderId+","+response.OrderDetailId+")'>comment</button></div>");
			
		    	$("#"+response.order.OrderId).append("<tr><td><img width='100px' height='154px' src='"+response.book.Picture+"'></td>\
                <td>"+response.book.BookName+"</td>\
                <td>$"+response.book.Price+"</td>\
                <td>&times;"+response.quantity+"</td>\
                <td>Total Price:&nbsp;$"+response.subTotal+"</td></tr>");
		}
	});
}

function doComment(bookId,orderId,orderDeatilId){
	$.ajax({
		url:"WriteCommentServlet",
		data:{"bookId":bookId,"commentContent":$("#commentArea").val(),"orderId":orderId,"orderDeatilId":orderDeatilId},
		type:"POST",
		success:function(response){
			console.log(response);
			if(response=="success"){
				console.log("1");
				$("#content").text("success");
			}else{
				
			}
		}
	});
}
function backToOrder(){
	window.location.href='MyOrder.jsp';
}